package com.ruoyi.dingmessage.impl;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiWorkrecordAddRequest;
import com.dingtalk.api.response.OapiWorkrecordAddResponse;
import com.ruoyi.dingmessage.ITodoService;
import com.ruoyi.system.service.impl.CorpTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DingTodoService  implements ITodoService<OapiWorkrecordAddRequest> {

    @Autowired
    private CorpTokenService corpTokenService;
    /**
     * @param userId
     * @param request
     * @return
     */
    @Override
    public boolean sendTodoByUserId(String userId, OapiWorkrecordAddRequest request,String corpId) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/workrecord/add");

        OapiWorkrecordAddResponse rsp = null;
        try {
            rsp = client.execute(request, corpTokenService.getCorpToken(corpId));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return rsp.isSuccess();
    }
}
